package com.fmjava.controller;


import com.fmjava.ServiceImpl.NewsServiceImpl;
import com.fmjava.domain.PageBean;
import com.fmjava.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/NoticeSearchServlet")
public class NoticeSearchServlet extends HttpServlet {
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //取数据
        NewsService newService = new NewsServiceImpl();

        //处理分页操作
        String currentPage = request.getParameter("currentPage");//获取当前页数
        String pageSize = request.getParameter("pageSize");
        if (currentPage == null || "".equals(currentPage)) {
            currentPage = "1";//默认显示第一页
        }
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = "3";//默认显示前3行数据
        }
        // List<News> newsList=newService.getNewsWithCategory(cacheKey);
        PageBean searchList = newService.getSearchBean(currentPage, pageSize, request.getParameter("search"));
        request.setAttribute("searchList", searchList);
//        System.out.println(request.getParameter("search"));
//        System.out.println(searchList);
        request.setAttribute("search",request.getParameter("search"));
        request.getRequestDispatcher("/WEB-INF/search_list.jsp").forward(request, response);

    }

}
